﻿using Girvs.Cache.Configuration;
using Girvs.Infrastructure;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Girvs.SignalR
{
    public class SignalRModule: IAppModuleStartup
    {
        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            var signalServiceBuilder = services.AddSignalRCore();
            var cacheConfig = EngineContext.Current.GetAppModuleConfig<CacheConfig>();
            if (cacheConfig.EnableCaching && cacheConfig.DistributedCacheType == CacheType.Redis)
            {
                signalServiceBuilder.AddRedis(cacheConfig.RedisCacheConfig.ConnectionString);
            }
        }

        public void Configure(IApplicationBuilder application)
        {
            
        }

        public void ConfigureMapEndpointRoute(IEndpointRouteBuilder builder)
        {
            builder.AutoMapSignalREndpointRouteBuilder();
        }

        public int Order { get; } = 99903;
    }
}